﻿using AntdUI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TCOChart
{
    public partial class MesFormEngrave : AntdUI.Window
    {
        AntList<ConsumeStatistic> ConsumeStatistics;
        public MesFormEngrave()
        {
            InitializeComponent();

            initTable();
            InitTableData();
        }

        void initTable()
        {
            table1.Columns = new AntdUI.ColumnCollection
            {
                new AntdUI.Column("Seq", "序号", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("Machine", "机种", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("ComsumeName", "耗材名称", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("Location", "位置", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("Unit", "单位", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("TotalLifespan", "总寿命", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("UsedNum", "已使用",AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("FirstAlarmThreshold", "首次报警阈值", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("InctAlarmThreshold", "增量报警阈值", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("ChangeTime", "更换时间", AntdUI.ColumnAlign.Center).SetLocalizationTitleID("Table.Column."),
                new AntdUI.Column("Btn", "操作").SetFixed().SetWidth("auto").SetLocalizationTitleID("Table.Column."),
            };
            //table1.EditMode = AntdUI.TEditMode.DoubleClick;
            table1.Bordered = true;  // 显示边框
            table1.EnableHeaderResizing = true;  // 手动调整列宽度
            table1.DataSource = table1;
        }

        void InitTableData()
        {
            ConsumeStatistics = new AntList<ConsumeStatistic>();
            // 加载数据

            for(int i = 0; i < 16; i++)
            {
                ConsumeStatistic consumeStatistic = new ConsumeStatistic();
                consumeStatistic.Seq = i;
                consumeStatistic.Machine = "机种1";
                consumeStatistic.ComsumeName = "吸嘴" + i;
                consumeStatistic.Location = "位置" + i;
                consumeStatistic.Unit = "次";
                consumeStatistic.TotalLifespan = "200000";
                consumeStatistic.UsedNum = "19800";
                consumeStatistic.FirstAlarmThreshold = "198000";
                consumeStatistic.InctAlarmThreshold = "200";
                consumeStatistic.ChangeTime = "2025-03-01 05:32:56";

                ConsumeStatistics.Add(consumeStatistic);
            }

            table1.Binding(ConsumeStatistics);
        }
    }


    public class ConsumeStatistic : AntdUI.NotifyProperty
    {
        public ConsumeStatistic() {
            Seq = 0;
            Machine = string.Empty;
            Location = string.Empty;
            Unit = string.Empty;
            TotalLifespan = string.Empty;
            UsedNum = string.Empty;
            FirstAlarmThreshold  = string.Empty;
            InctAlarmThreshold = string.Empty;
            ChangeTime = string.Empty;
            ComsumeName = string.Empty;
            _editButton = new AntdUI.CellButton(Guid.NewGuid().ToString(), "更换完成", TTypeMini.Primary);
        }
        /// <summary>
        /// 序号
        /// </summary>
        public int Seq { get; set; }
        public string Machine { get; set; }
        public string Location { get; set; }
        public string Unit { get; set; }
        public string TotalLifespan { get; set; }
        public string UsedNum { get; set; }
        public string FirstAlarmThreshold { get; set; }
        public string InctAlarmThreshold { get; set; }
        public string ChangeTime { get; set; }
         
        public string ComsumeName { get; set; }

        AntdUI.CellButton _editButton;
        public AntdUI.CellButton Btn
        {
            get => _editButton;
            set
            {
                _editButton = value;
                OnPropertyChanged();
            }
        }
    }
}
